package cn.miju.unionpay.response;

import cn.miju.common.content.CodeMessage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Map;
import java.util.Set;

/**
 * <pre>
 * api返回基础信息
 * </pre>
 *
 * @author zhuming
 * @version 1.0.0
 * @since 2023-03-03 16:40
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class UnionPayBaseResp {
    /**
     * 接口返回码
     */
    private Integer code;
    /**
     * 接口返回信息
     */
    private String msg;
    /**
     * 可选返回参数(如果接口所需参数不满足需求，可按照官方接口文档，原样传入对应参数)
     */
    private Map<String, Object> optionalRespParams;

    public static UnionPayBaseResp preBuilder(CodeMessage codeMessage, UnionPayBaseResp... source) {
        UnionPayBaseResp baseResp = null;
        if (null != source && source.length > 0) {
            baseResp = source[0];
        } else {
            baseResp = new UnionPayBaseResp();
        }
        baseResp.setCode(codeMessage.getCode());
        baseResp.setMsg(codeMessage.getMessage());
        return baseResp;
    }

    public boolean isSuccess() {
        return CodeMessage.SUCCESS.getCode().equals(code);
    }
}
